home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
util
/
startup.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
5KB
|
104 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
import platform
import os.path as os
from logging import getLogger, StreamHandler
log = getLogger('startup')
log.addHandler(StreamHandler())
_myplatform = platform.platform(terse = True).split('-')[0]
def enable(program_path, nice_name, *args):
func_name = 'enable_' + _myplatform
if not nice_name:
pass
program_name = app_name(program_path)
globals()[func_name](program_path, program_name, *args)
log.info('%s will launch on startup', program_name)
def disable(program_name):
func_name = 'disable_' + _myplatform
globals()[func_name](program_name)
log.info('%s removed from startup', program_name)
def is_enabled(program_name):
return globals()['is_enabled_' + _myplatform]()
def app_name(program_path):
return os.path.split(program_path)[-1].split('.')[0]
def enable_Darwin(program_path, program_name, *args):
username = os.environ.get('USER')
home = os.environ.get('HOME')
folderpath = home + '/Library/LaunchAgents'
plistpath = home + '/Library/LaunchAgents/%(program_name)s.plist' % locals()
if not os.path.isdir(folderpath):
os.mkdir(folderpath)
if not os.path.isfile(plistpath):
contents = '<?xml mersion="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple Computer//DTDPLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0">\n<dict>\n <key>Label</key>\n <string>%(program_name)s</string>\n <key>OnDemand</key>\n <true/>\n <key>ProgramArguments</key>\n <array>\n <string>%(program_path)s</string>\n' % locals()
contents += ''.join((lambda .0: for arg in .0:
'<string>%s</string>' % arg)(args)) + '\n </array>\n <key>RunAtLoad</key>\n <true/>\n <key>ServiceDescription</key>\n <string>This plist launches a the specified program at login.</string>\n <key>UserName</key>\n <string>%(username)s</string>\n </dict>\n</plist>\n' % locals()
f = open(plistpath, 'w')
f.writelines(contents)
f.close()
else:
log.warning('There is already a startup item')
def disable_Darwin(program_name):
home = os.environ.get('HOME')
plistpath = home + '/Library/LaunchAgents/%(program_name)s.plist'
if os.path.isfile(plistpath):
os.remove(plistpath)
else:
log.warning('There was no plist file to remove!')
def is_enabled_Darwin(program_name):
home = os.environ.get('HOME')
path = home + '/Library/LaunchAgents/%s.plist' % program_name
return os.path.isfile(path)
def _startup_regkey():
import _winreg as _winreg
return _winreg.OpenKeyEx(_winreg.HKEY_CURRENT_USER, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run', 0, _winreg.KEY_ALL_ACCESS)
def enable_Windows(program_path, program_name, *args):
import _winreg
key = _startup_regkey()
regval = program_path + ' ' + ' '.join(args)
_winreg.SetValueEx(key, program_name, 0, _winreg.REG_SZ, regval)
_winreg.CloseKey(key)
def disable_Windows(program_name):
import _winreg
key = _startup_regkey()
try:
_winreg.DeleteValue(key, program_name)
except WindowsError:
log.warning('startup.disable could not delete registry key')
_winreg.CloseKey(key)
def is_enabled_Windows(program_name):
import _winreg
key = _startup_regkey()
try:
_winreg.QueryValueEx(key, program_name)
return True
except WindowsError:
return False